<template>
  <div style="padding-top:30px">
      <div>
          <!-- <pdf-header :pdfData="searchData"></pdf-header> -->
      </div>
    <div v-for="item in searchFileData" :key="item.id">
      <pdf-item class="pdf-item" :pdfData="item"></pdf-item>
    </div>
  </div>
</template>

<script>
import pdfItem from "./pdfItem.vue";
import pdfHeader from "../../components/pdfHeader.vue"
export default {
  components: {
    pdfItem,
    pdfHeader
  },
  data() {
    return {
      searchFileData: [],
    };
  },
  created() {
    this.searchFile();
  },
  methods: {
    filterSearch() {
      let templateArr = [];
      this.AllFileData.filter((item) => {
        return item.name.indexOf(this.searchData) > -1;
      }).forEach((item) => {
        let isAll = true;
        templateArr.forEach((items, index) => {
          if (templateArr[index][item.type]) {
            isAll = false;
            templateArr[index][item.type].push(item);
          }
        });
        if (isAll) {
          templateArr.push({ [item.type]: [item] });
        }
      });
      this.searchFileData = templateArr;
      
    },
    searchFile() {
      this.$axios.post("/pdf/search").then((res) => {
        let data = res.data;
        this.AllFileData = res.data.data;
        let templateArr = [];
        data.error === -1 &&
          data.data.forEach((item) => {
            let isAll = true;
            templateArr.forEach((items, index) => {
              if (templateArr[index][item.type]) {
                isAll = false;
                templateArr[index][item.type].push(item);
              }
            });
            if (isAll) {
              templateArr.push({ [item.type]: [item] });
            }
          });
        this.searchFileData = templateArr;
        console.log(templateArr);
        
      });
    },
  },
};
</script>

<style>
</style>